package com.ioPackage;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @ClassName Test1
 * @Description 文章排序并拷贝
 * @Author 2214361854
 * @Date 2022/3/1 11:08
 * @Version 1.0
 */
public class Test1 {
    public static void main(String[] args) {
        try(
            BufferedReader br = new BufferedReader(new FileReader("src\\text02.txt"));
            BufferedWriter bw = new BufferedWriter(new FileWriter("src\\text02.txt",true));
            ) {
            List<String> dates = new ArrayList<>();
            String line;
            while ((line = br.readLine()) != null) {
                dates.add(line);
            }
            System.out.println(dates);

            //默认排序
//            Collections.sort(date);
//            System.out.println(date);

//            定义排序依据
            List<String> sizes = new ArrayList<>();
            Collections.addAll(sizes,"清","江","两","不");

//            Collections.sort(dates, new Comparator<String>() {
//                @Override
//                public int compare(String o1, String o2) {
//                    //(o1.substring(0,indexof(".")))
//                    return sizes.indexOf(o1.substring(2,3)) - sizes.indexOf(o2.substring(2,3));
//                }
//            });

//            lambda
            Collections.sort(dates, (o1,o2)-> sizes.indexOf(o1.substring(2,3)) - sizes.indexOf(o2.substring(2,3)));

            System.out.println(dates);

            //拷贝
            for (String date : dates) {
                bw.write(date);
                bw.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
